const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = [
    {
        test: /\.tpl$/,
        use: [
            'babel-loader',
            {
                loader: path.resolve(__dirname, './loader/tpl_loader.js'),
                options: {
                    name: 1
                }
            }
        ]
    },
    {
        test: /\.js$/,
        use: [
            {
                loader: 'thread-loader',
                options: {
                    workers: require('os').cpus().length - 1 // // 开启2个worker
                }
            },
            'babel-loader'
        ],
        exclude: /node_modules/
    },
    {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: 'asset',
        parser: {
            dataUrlCondition: {
                maxSize: 2 * 1024
            }
        },
        generator: {
            filename: 'images/[name].[hash:8][ext]' // 生成路径
        },
        // use: [
        //     {
        //         loader: 'image-webpack-loader',
        //         options: {
        //             mozjpeg: {
        //                 progressive: true,
        //                 quality: 65
        //             },
        //             optipng: {
        //                 enable: false
        //             },
        //             pngquant: {
        //                 quality: [0.65, 0.90],
        //                 speed: 4
        //             },
        //             gifsicle: {
        //                 interlaced: false,
        //             },
        //             webp: {
        //                 quality: 75
        //             }
        //         }
        //     }
        // ]
    },
    {
        test: /\.css$/, 
        use: [
            //'style-loader',
            MiniCssExtractPlugin.loader, // 替代 style-loader，提取出 CSS
            'css-loader'
        ]
    },
    {
        test: /\.(woff|woff2|eot|ttf|otf)$/i,
        type: 'asset/resource',
    },
]